package com.example.test;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class Process_Leave_Demo {

    /**
     * 部署流程
     * act_re_deployment 部署信息
     * act_ge_bytearray 二进制文件表
     * act_re_procdef 流程定义
     */
    @Test
    public void createTask() {
        //1.创建核心对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();

        //2.获取到发布对象
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();

        //3.任务发布
        String bpmnUrl = "BPMN/请假流程.bpmn";
        String pngUrl = "BPMN/请假流程.png";
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource(bpmnUrl)
                .addClasspathResource(pngUrl)
                .name("请假流程")
                .deploy();
        System.out.println(deployment.getId());
        System.out.println(deployment.getKey());
        System.out.println(deployment.getName());
        System.out.println(deployment.getCategory());
    }

    /**
     * 启动任务
     * act_hi_actinst 流程实例执行历史
     * act_hi_identitylink 流程的参与用户信息历史
     * act_hi_procinst 流程实例历史信息
     * act_hi_taskinst 流程任务的历史信息
     * act_ru_execution 流程正在执行的历史信息
     * act_ru_identitylink 流程的参与用户信息
     * act_ru_task 任务信息
     */
    @Test
    public void initTask() {
        //1.创建核心对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.获取启动对象
        RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
        //3.启动任务
        ProcessInstance process_leave = runtimeService.startProcessInstanceByKey("Process_Leave");
        System.out.println("process_leave = " + process_leave);
    }


}
